import 'learning_item.dart';

/// 用户偏好数据结构
class UserPreference {
  final int? preferredGrade;
  final String? preferredSubject;
  final String? preferredModule;
  final Map<String, int> subjectInterests; // 学科兴趣度
  final Map<String, int> moduleInterests; // 模块兴趣度
  final Map<ContentType, int> typePreferences; // 内容类型偏好

  UserPreference({
    this.preferredGrade,
    this.preferredSubject,
    this.preferredModule,
    this.subjectInterests = const {},
    this.moduleInterests = const {},
    this.typePreferences = const {},
  });

  /// 更新学科兴趣度
  UserPreference updateSubjectInterest(String subject, int interest) {
    final newInterests = Map<String, int>.from(subjectInterests);
    newInterests[subject] = interest;
    return UserPreference(
      preferredGrade: preferredGrade,
      preferredSubject: preferredSubject,
      preferredModule: preferredModule,
      subjectInterests: newInterests,
      moduleInterests: moduleInterests,
      typePreferences: typePreferences,
    );
  }

  /// 更新模块兴趣度
  UserPreference updateModuleInterest(String module, int interest) {
    final newInterests = Map<String, int>.from(moduleInterests);
    newInterests[module] = interest;
    return UserPreference(
      preferredGrade: preferredGrade,
      preferredSubject: preferredSubject,
      preferredModule: preferredModule,
      subjectInterests: subjectInterests,
      moduleInterests: newInterests,
      typePreferences: typePreferences,
    );
  }

  /// 更新内容类型偏好
  UserPreference updateTypePreference(ContentType type, int preference) {
    final newPreferences = Map<ContentType, int>.from(typePreferences);
    newPreferences[type] = preference;
    return UserPreference(
      preferredGrade: preferredGrade,
      preferredSubject: preferredSubject,
      preferredModule: preferredModule,
      subjectInterests: subjectInterests,
      moduleInterests: moduleInterests,
      typePreferences: newPreferences,
    );
  }
}